package com.webapp.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;


public class FilseInterceptor implements HandlerInterceptor {
	protected final Logger logger=Logger.getLogger(this.getClass());
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		String url = request.getRequestURI();
		logger.info("url====:"+request.getRequestURI());
		Object sessionObj = request.getSession().getAttribute("admin");  
	    if(sessionObj!=null) {
	      return true;  
	    }
	    
	    logger.info("url have no session:"+request.getRequestURI());
	    response.sendRedirect(request.getContextPath()+"/jsp/user/login.jsp");  
	    return false;
	}
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub

	}
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub

	}

}
